package com.tianma315.admin.check.controller;


import java.util.Arrays;

import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.check.domain.RecordArrtDO;
import com.tianma315.admin.check.service.RecordArrtService;

/**
 * 
 * <pre>
 * 检测记录属性
 * </pre>
 * <small> 2019-05-28 16:30:58 | Aron</small>
 */
@Controller
@RequestMapping("/check/recordArrt")
public class RecordArrtController {
	@Autowired
	private RecordArrtService recordArrtService;
	
	@GetMapping()
	@RequiresPermissions("check:recordArrt:recordArrt")
	String RecordArrt(){
	    return "check/recordArrt/recordArrt";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("check:recordArrt:recordArrt")
	public Result<Page<RecordArrtDO>> list(Integer pageNumber, Integer pageSize, RecordArrtDO recordArrtDTO){
		// 查询列表数据
        Page<RecordArrtDO> page = new Page<>(pageNumber, pageSize);
        
        Wrapper<RecordArrtDO> wrapper = new EntityWrapper<RecordArrtDO>(recordArrtDTO);
        page = recordArrtService.selectPage(page, wrapper);
        int total = recordArrtService.selectCount(wrapper);
        page.setTotal(total);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("check:recordArrt:add")
	String add(){
	    return "check/recordArrt/add";
	}

	@GetMapping("/edit/{recordArrtId}")
	@RequiresPermissions("check:recordArrt:edit")
	String edit(@PathVariable("recordArrtId") Integer recordArrtId,Model model){
		RecordArrtDO recordArrt = recordArrtService.selectById(recordArrtId);
		model.addAttribute("recordArrt", recordArrt);
	    return "check/recordArrt/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("check:recordArrt:add")
	public Result<String> save( RecordArrtDO recordArrt){
		if(recordArrtService.insert(recordArrt)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("check:recordArrt:edit")
	public Result<String>  update( RecordArrtDO recordArrt){
		recordArrtService.updateById(recordArrt);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("check:recordArrt:remove")
	public Result<String>  remove( Integer recordArrtId){
		if(recordArrtService.deleteById(recordArrtId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("check:recordArrt:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] recordArrtIds){
		recordArrtService.deleteBatchIds(Arrays.asList(recordArrtIds));
		return Result.ok();
	}
	
}
